<?php

declare(strict_types=1);

namespace Plugin\Attractions\Commerce\Common;

use Common\Common;

class IDGenerator
{
     const KEY_PREFIX = 'attraction:commerce:id:';
     const ORDER = 'order:';
     const CONTRACT = 'contract:';
     const ENERGY = 'energy:';
     const SETTLEMENT = 'settlement:';

     public static function getID($type): int
     {
          $redis = Common::redis();
          $date = date('ymd');
          $suffix = $redis->incr(self::KEY_PREFIX . $type . $date);
          $random = random_int(0, 9999);
          return intval(sprintf('%s%06d%04d',$date, $suffix, $random));
     }
}